<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<head th:include="header">
    <title>角色管理-添加</title>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox-content">
            <form id="fm" class="form-horizontal" data-validator-option="{timely:8, focusCleanup:true, theme:'simple_bottom'}">
                <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
                <div class="form-group">
                    <label class="col-sm-3 control-label">角色</label>
                    <div class="col-sm-6">
                        <input type="text" class="form-control" name="name"  data-rule="角色:required;length(2~16)">
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">描述</label>
                    <div class="col-sm-6">
                        <input type="text" class="form-control" name="description"  data-rule="描述:required;length(2~16)">
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">排序</label>
                    <div class="col-sm-6">
                        <input type="text" class="form-control" name="seq"  data-rule="排序:required;integer[+0],length(~2)">
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">角色状态</label>
                    <div class="col-sm-6">
                        <select class="form-control" name="status">
                            <option value="0">正常</option>
                            <option value="1">停用</option>
                        </select>
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group">
                    <div class="text-center">
                        <button class="btn btn-primary" type="submit">提 交</button>
                        <button class="btn btn-white" type="reset">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div th:include="footer"></div>
    <script type="text/javascript" th:inline="javascript">
        $("#fm").validator({
            valid: function (form) {
                var me = this;
                // 提交表单之前，hold住表单，防止重复提交
                me.holdSubmit();
                $.ajax({
                    url: basePath+"role/edit",
                    data: $(form).serialize(),
                    type: "POST",
                    dataType: 'json',
                    success: function (data) {
                        if (data.success) {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.msg(data.msg,{
                            	  icon: 1,
                            	  time: 2000 //2秒关闭（如果不配置，默认是3秒）
                            	},function () {
                            	window.parent.location.reload();
                                parent.layer.close(index);
                            });
                            
                        } else {
                        	parent.layer.msg(data.msg,{
                          	  icon: 2,
                        	  time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        	});
                            me.holdSubmit(false);
                        }
                    }
                });
            }
        });
    </script>
</body>
</html>